<template>
    <div>
        <city-list
            :isCountry="this.isCountry"
            :isCity="this.isCity"
            :isViews="this.isViews"
            :country="this.country"
            :city="this.city"
            :views="this.views"></city-list>
        <div class="city-detail-content" v-html="content"></div>
    </div>
</template>

<script>
import CityList from "@/components/CityList";
import Card from "@/components/Card";
import { Util } from "@/js/Util";
export default {
  components: {
    CityList,
    Card
  },
  mounted() {
    this.init();
    this.getList();
  },
  data() {
    return {
      isCountry: true,
      isCity: true,
      isViews: true,
      country: "",
      city: "",
      views: "",
      content: ""
    };
  },
  methods: {
    hasQuery() {
      let countryId = this.$route.query.countryId,
        country = this.$route.query.country,
        cityId = this.$route.query.cityId,
        city = this.$route.query.city,
        viewsId = this.$route.query.viewsId,
        views = this.$route.query.views;
      if (!countryId || !country || !cityId || !city || !viewsId || !views) {
        this.$router.push({ name: "juejia_index" });
        return false;
      }
    },
    init() {
      this.hasQuery();
      this.country = decodeURIComponent(this.$route.query.country);
      this.city = decodeURIComponent(this.$route.query.city);
      this.views = decodeURIComponent(this.$route.query.views);
      this.isFirst();
    },
    getList() {
      this.$vux.loading.show({ text: "Loading" });
      let id = this.$route.query.viewsId,
        country = this.$route.query.country,
        city = this.$route.query.city;
      this.$http.get("scenery/CityScenery/v1?sceneryId=" + id).then(
        response => {
          this.$vux.loading.hide();
          let result = response.data;
          if (result.code) {
            this.$vux.toast.text(result.message, "bottom");
            return false;
          }
          this.content = decodeURIComponent(result.data.content);
        },
        response => {
          Util.errorWarning(this);
        }
      );
    },
    // 判断是否为直接进入
    isFirst() {
      // 存在 sessionStorage，表示通过正常操作进入页面
      if (sessionStorage.getItem("MeiJingKu_history")) {
        // 添加浏览记录
        Util.setHistory(this);
      }
    }
  }
};
</script>

<style lang="less" scoped="scoped">
.city-detail-content {
  padding-top: 5.5rem;
  width: 90%;
  display: block;
  margin: 0 auto;
}
</style>